# setup
#编译选项
COMPILE_OPTS = -c -mcpu=cortex-m3  -mthumb  -mlittle-endian  -Wall -g -Werror
#包含的文件目录
INCLUDE_DIRS = -I inc  

OBJ_DIR=obj

OBJS += $(patsubst %.c,%.o,$(wildcard src/*.c))
OBJS += $(patsubst %.s,%.o,$(wildcard Startup/*.s))
OBJS += $(patsubst %.c,%.o,$(wildcard Startup/*.c))

CC = arm-none-eabi-gcc
CFLAGS = $(COMPILE_OPTS) $(INCLUDE_DIRS) -D STM32F10X_MD -D VECT_TAB_FLASH  -D USE_STDPERIPH_DRIVER

CXX = arm-none-eabi-g++
CXXFLAGS = $(COMPILE_OPTS) $(INCLUDE_DIRS)

AS = arm-none-eabi-gcc
ASFLAGS = $(COMPILE_OPTS) -c

LD = arm-none-eabi-gcc
LDFLAGS =  -T stm32.ld -Wl,-Map=output.map

OBJCP = arm-none-eabi-objcopy
OBJCPFLAGS = -O binary
#link option
AR = arm-none-eabi-ar
ARFLAGS = cr

LIBST32=libstm32.a
# libstm32.a

all:$(LIBST32)


$(LIBST32): $(OBJS)
	@echo "Building $@ ..." 
	@$(AR) cr libstm32.a $(OBJS)
	@echo "Building $@ Success!"

%.o:%.s
	@echo CC: $<
	@$(CC) $(CFLAGS) -c $< -o $@
%.o:%.c
	@echo CC: $<
	@$(CC) $(CFLAGS) -c $< -o $@


clean:
	@echo "Clean libstm32 OBJS..."
	@-rm    *.a $(OBJS)
	@echo "Clean Done ..."
